home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 25
/
CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso
/
CUCD
/
Magazine
/
C_Tutorial
/
Part-11
/
req1
/
arexx.c
next >
Wrap
C/C++ Source or Header
|
1998-03-02
|
2KB
|
75 lines
#include "arexx.h"
#include<clib/alib_protos.h>
#include<clib/exec_protos.h>
#include<clib/rexxsyslib_protos.h>
#include<stdio.h>
#include<string.h>
static struct MsgPort* arexxport = NULL;
int createARexxPort(char* portname)
{
int success = FALSE;
char* error = NULL;
/* First, must turn off multi-tasking so we can atomicly add our port */
Forbid();
/* We can only succeed if the named port doesn't already exist */
if(FindPort(portname) == NULL)
{
/* At last, make the port (priority 1 to enable fast searching) */
if(arexxport = CreatePort(portname, 1))
success = TRUE;
else
error = "Error: cannot create ARexx port\n";
}
else
error = "Error: cannot create ARexx port (the name already exists)\n";
/* We must now turn multi-tasking back on... */
Permit();
/* ...now we can print any error and return the result */
if(error)
printf(error);
return success;
}
void freeARexxPort()
{
if(arexxport)
{
struct RexxMsg* msg;
/* First, make the port private so we get no more messages */
RemPort(arexxport);
/* Now clear out any outstanding messages... */
/* (Passing 20 for rc indicates an error reply) */
while(msg = getARexxMsg())
replyARexxMsg(msg, 20, NULL);
/* ...and now it's safe to delete the port */
DeletePort(arexxport);
arexxport = NULL;
}
}
ULONG getARexxSig()
{
return arexxport ? 1L << arexxport->mp_SigBit : 0L;
}
struct RexxMsg* getARexxMsg()
{
return (struct RexxMsg*)GetMsg(arexxport);
}
void replyARexxMsg(struct RexxMsg* msg, LONG rc, char* result)
{
/* Set up reply result values */
msg->rm_Result1 = rc;
msg->rm_Result2 = NULL;
/* If the reply expects a result string, create one */
if((msg->rm_Action & RXFF_RESULT) && rc == 0 && result != NULL)
msg->rm_Result2 = (LONG)CreateArgstring(result, strlen(result));
/* Now we can reply to the message */
ReplyMsg((struct Message*)msg);
}